_Pragma("once");

#include "MultiPage.h"
#include "EditablePage.h"
#include "StringListEditor.h"
#include "common.h"
#include "NetworkManager.h"
#include "ConfigManager.h"



class NetworkManagePage : public MultiPage<EditablePage> {
public:
    using super =  MultiPage<EditablePage>;

    static constexpr char UNKNOWN_INFORMATION[] = "***";

    NetworkManagePage(const int pageNum) : super(pageNum), mnetworkManager(NetworkManagerSingleton::instance()) {
        mpageSize = 4;
    }


/*
    void initialize() override {

    }

    void beforeDisplay() override {

        initEditors();
    }


    void afterDisplay() override {
        editUnits.clear();
    }*/


    void initEditors() override {
        StringListEditor* pEditor;

        pEditor = new StringListEditor(2, 5, 15, networkModeVector);
        editUnits.push_back(BasicEditorSharedPtr(pEditor));
    }


    void paint() override;


void setFocus(bool focus) override {
    if (0 == mmultiPageNo){
        super::setFocus(focus);
    }
}


    void setValue() override {
        static_cast <StringListEditor*>(editUnits[0].get())->setValue(mnetworkManager.mtype);
    }


    void saveValue() override {
      //  if (0 == this->mmultiPageNo) {
      NetworkType networkType = static_cast <NetworkType>(static_cast <StringListEditor*>(editUnits[0].get())->getValue());

      ConfigManager& configManager = ConfigManagerSingleton::instance();
      configManager.getConfigInfo().networkType = networkType;
      configManager.saveConfigInfo();

      mnetworkManager.setActiveNetwork(networkType, mnetworkManager.getActiveNetwork(networkType));
    //}
    }

protected:
    NetworkManager& mnetworkManager;

};
